package org.jeecg.modules.bj.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.bj.entity.BjGwbd;
import org.jeecg.modules.bj.entity.Lwgzlsb;
import org.jeecg.modules.bj.entity.Ygdab;
import org.jeecg.modules.bj.mapper.YgdabMapper;
import org.jeecg.modules.bj.service.ILwgzlsbService;
import org.jeecg.modules.bj.service.IYgdabService;
import org.jeecg.modules.bj.service.OpBjDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DS("bj")
public class OpBjDbServiceImpl extends ServiceImpl<YgdabMapper, Ygdab> implements OpBjDbService {
    @Autowired
    private IYgdabService ygdabService;
    @Autowired
    private ILwgzlsbService lwgzlsbService;

    @Override
    @DS("bj")
    public void updateYgdab(String ygid,int workstate){
        Ygdab ygdab=ygdabService.getYadabById(ygid);
        ygdab.setWorkstate(workstate);
        ygdabService.updateById(ygdab);
    }

    @Override
    @DS("bj")
    public void updateYgdabForGwbd(String ygid, BjGwbd bjGwbd){
        Ygdab ygdab=ygdabService.getYadabById(ygid);
        ygdab.setBmname(bjGwbd.getNewbm());
        ygdab.setGwname(bjGwbd.getNewgw());
        //ygdab.setPaysmonth(bjGwbd.getNewjbgz());
        ygdabService.updateById(ygdab);

        List<Lwgzlsb> list=lwgzlsbService.getListByYgid(ygdab.getId());
        if(list.size()>0){
            Lwgzlsb lwgzlsb=list.get(0);
            bjGwbd.setOldbasic(lwgzlsb.getXjJcgz());
            lwgzlsb.setXjJcgz(bjGwbd.getNewjbgz());
            lwgzlsbService.updateById(lwgzlsb);

        }
    }
}
